package com.danciyixue.boot.client.testRecord.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Min;
import jakarta.validation.Valid;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 测试记录保存请求对象
 *
 * @author youlaitech
 * @since 2025-07-27
 */
@Getter
@Setter
@Schema(description = "测试记录保存请求对象")
public class TestRecordSaveRequest implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "测试ID", example = "11")
    @NotNull(message = "测试ID不能为空")
    private String testId;

    @Schema(description = "用户ID", example = "1")
    @NotNull(message = "用户ID不能为空")
    private Long userId;

    @Schema(description = "单元ID", example = "1")
    @NotNull(message = "单元ID不能为空")
    private Long unitId;

    @Schema(description = "测试得分", example = "10")
    @NotNull(message = "测试得分不能为空")
    @Min(value = 0, message = "测试得分不能为负数")
    private Integer score;

    @Schema(description = "测试耗时(秒)", example = "220")
    @NotNull(message = "测试耗时不能为空")
    @Min(value = 0, message = "测试耗时不能为负数")
    @JsonProperty("time_spent")
    private Integer timeSpent;

    @Schema(description = "错误单词ID列表", example = "9,7,10,6,1,8,5,3,2")
    @JsonProperty("wrong_word_ids")
    private String wrongWordIds;

    @Schema(description = "正确单词ID列表", example = "4")
    @JsonProperty("right_word_ids")
    private String rightWordIds;

    @Schema(description = "未选择单词ID列表", example = "")
    @JsonProperty("unchoose_word_ids")
    private String unchooseWordIds;

    @Schema(description = "用户答案列表")
    @Valid
    @JsonProperty("userAnswers")
    private List<UserAnswer> userAnswers;

    /**
     * 用户答案内部类
     */
    @Getter
    @Setter
    @Schema(description = "用户答案")
    public static class UserAnswer implements Serializable {

        @Serial
        private static final long serialVersionUID = 1L;

        @Schema(description = "单词ID", example = "4")
        @NotNull(message = "单词ID不能为空")
        @JsonProperty("wordId")
        private String wordId;

        @Schema(description = "问题类型", example = "etcTranslation")
        @NotNull(message = "问题类型不能为空")
        @JsonProperty("questionType")
        private String questionType;

        @Schema(description = "用户答案索引", example = "0")
        @NotNull(message = "用户答案索引不能为空")
        @JsonProperty("userAnswerIndex")
        private Integer userAnswerIndex;

        @Schema(description = "是否正确", example = "true")
        @NotNull(message = "是否正确不能为空")
        @JsonProperty("isCorrect")
        private Boolean isCorrect;
    }
}
